import React from 'react';
import { message } from 'antd';
import {withRouter} from 'react-router-dom'
import axios from '../../../../../utils/http'
import * as api from '../../../../../utils/api'
import {inject,observer} from 'mobx-react'
import {toJS} from 'mobx'
// 售后 操作备注页面
@inject('curOrder')
@observer
class OperatePage extends React.Component{
    constructor(){
        super()
        this.state={
            beiZhu:''
        }
    }
    huiDaoOrderDetail = (obj)=>{
        let curOrderDataOperateArr = toJS(this.props.curOrder.curOrderDataOperateArr)
        let curOrderDataArr = toJS(this.props.curOrder.curOrderDataArr)
        console.log(curOrderDataOperateArr)
        console.log(curOrderDataArr)

        if(obj === 1){
            if(this.state.beiZhu!==''){
            //向后台发起请求添加当前订单的操作备注信息
                axios({
                    url:api.POST_ADDREMARKS,
                    method:'POST',
                    data:{
                        delivNum: curOrderDataOperateArr[0].delivNum,
                        delivStatu: curOrderDataOperateArr[0].delivStatu,
                        modeDis: curOrderDataOperateArr[0].modeDis,
                        opera: "当前登录者",
                        orderId: curOrderDataArr[0].orderId,
                        ordoperDesc: this.state.beiZhu,
                        payStatu: curOrderDataOperateArr[0].payStatu
                      }
                }).then(data=>{
                    console.log(data)
                    this.props.history.push('/Home/dingDan/Orderlist/Orderdetail')
                })
            }else{
                message.error('操作备注不能为空!!!')
            }
        }else{
             /* 跳转到订单详情页面 */
             this.props.history.push('/Home/dingDan/Orderlist/Orderdetail')
        }
    }
    changeOperateVal = (e)=>{
        this.setState({
            beiZhu:e.target.value
        })
    }
    render(){
        return(
            <div>
                <div className="peratePage">
                    <h1>操作备注</h1>
                    <div>
                        操作备注 : <textarea name="" id="" cols="80" rows="3" onChange={this.changeOperateVal}></textarea>
                    </div>
                    <div className="btnBox">
                        <button className="copyBtn" onClick={()=>this.huiDaoOrderDetail(1)}>确定</button>
                        <button className="copyBtn" onClick={()=>this.huiDaoOrderDetail(2)}>返回</button>
                    </div>
                </div>
            </div>
        )
    }
}
export default withRouter(OperatePage)